/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { BuildStatus, OutputType } from './common-enum.js';

export type Message = object;

export interface OutputMessage extends Message {
  type: OutputType;
  text: string | Uint8Array;
  encoding?: BufferEncoding;
}

export function createOutput(type: OutputType, text: string | Uint8Array, encoding?: BufferEncoding): OutputMessage {
  return { type, text, encoding };
}

export interface BuildStatusMessage extends Message {
  status: BuildStatus;
  exitCode?: number;
  reason?: string;
}

export function createBuildStatus(status: BuildStatus, exitCode?: number, reason?: string): BuildStatusMessage {
  return { status, exitCode, reason };
}

export interface Command extends Message {
  reason: string;
}

export type CancelBuildCommand = Command;

export type StopDaemonCommand = Command;
